package org.sirmupadbapi.persistencia;

import org.sirmupadbapi.beans.Comercios;
import java.sql.Date; 
import org.sirmupadbapi.beans.*;
import org.sirmupadbapi.controller.*;
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import java.util.*;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.util.Map;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
 import javax.sql.DataSource;
import org.sirmupadbapi.generales.Mensajeria;
import org.sirmupadbapi.generales.DataGManager;


/**
*
* @author
*/

public class ComerciosPersistencia implements Serializable {
private static final long serialVersionUID = 1L;
public static Exception excepcion;
public static boolean esMensaje = false;
public static Connection con = null;
public static java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/sirmupadbapi/properties/mensajes");
static DataGManager dataGManager;
static List<Comercios> list;

public ComerciosPersistencia(){
         esMensaje =false;
}


/**
*
* insert()
*/

public static boolean insert (Comercios comercios ) {
  excepcion = null;
  try {
      esMensaje =false;
   
   
   

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pinsert = null;
      String sql = "insert into comercios(IDCOMERCIO,CEDULA,COMERCIO,RUC,DESCRIPCION,DIRECCION,IDCORREGIMIENTO,TELEFONO,FECHA,HIPOTECADO,BAJADO,TRASPASO,SECUESTRADO,IDMUNICIPIO,ESTATAL,ACTIVO,IDUSUARIO)  values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
      pinsert = con.prepareStatement(sql);
              pinsert.setString(1,comercios.getIDCOMERCIO());
        pinsert.setString(2,comercios.getCEDULA());
        pinsert.setString(3,comercios.getCOMERCIO());
        pinsert.setString(4,comercios.getRUC());
        pinsert.setString(5,comercios.getDESCRIPCION());
        pinsert.setString(6,comercios.getDIRECCION());
        pinsert.setString(7,comercios.getIDCORREGIMIENTO());
        pinsert.setString(8,comercios.getTELEFONO());
        pinsert.setDate(9,comercios.getFECHA());
        pinsert.setString(10,comercios.getHIPOTECADO());
        pinsert.setString(11,comercios.getBAJADO());
        pinsert.setString(12,comercios.getTRASPASO());
        pinsert.setString(13,comercios.getSECUESTRADO());
        pinsert.setString(14,comercios.getIDMUNICIPIO());
        pinsert.setString(15,comercios.getESTATAL());
        pinsert.setString(16,comercios.getACTIVO());
        pinsert.setString(17,comercios.getIDUSUARIO());
      int filas= pinsert.executeUpdate();
      pinsert.close();
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
 }


/**
*
* update()
*/

public static boolean update(Comercios comercios ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update comercios set  IDCOMERCIO=?, CEDULA=?, COMERCIO=?, RUC=?, DESCRIPCION=?, DIRECCION=?, IDCORREGIMIENTO=?, TELEFONO=?, FECHA=?, HIPOTECADO=?, BAJADO=?, TRASPASO=?, SECUESTRADO=?, IDMUNICIPIO=?, ESTATAL=?, ACTIVO=?, IDUSUARIO=?  where  IDCOMERCIO ='"+comercios.getIDCOMERCIO()+"' and  IDMUNICIPIO ='"+comercios.getIDMUNICIPIO()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setString(1,comercios.getIDCOMERCIO());
pupdate.setString(2,comercios.getCEDULA());
pupdate.setString(3,comercios.getCOMERCIO());
pupdate.setString(4,comercios.getRUC());
pupdate.setString(5,comercios.getDESCRIPCION());
pupdate.setString(6,comercios.getDIRECCION());
pupdate.setString(7,comercios.getIDCORREGIMIENTO());
pupdate.setString(8,comercios.getTELEFONO());
pupdate.setDate(9,comercios.getFECHA());
pupdate.setString(10,comercios.getHIPOTECADO());
pupdate.setString(11,comercios.getBAJADO());
pupdate.setString(12,comercios.getTRASPASO());
pupdate.setString(13,comercios.getSECUESTRADO());
pupdate.setString(14,comercios.getIDMUNICIPIO());
pupdate.setString(15,comercios.getESTATAL());
pupdate.setString(16,comercios.getACTIVO());
pupdate.setString(17,comercios.getIDUSUARIO());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* update()
*/

public static boolean update(String sqlupdate ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update  comercios set " + sqlupdate +"";
      pupdate= con.prepareStatement(sql);
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* updatePrimaryKey()
*/

public static boolean updatePrimaryKey(Comercios comercios_old , Comercios comercios) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update comercios set  IDCOMERCIO=? ,  IDMUNICIPIO=?  where  IDCOMERCIO ='"+comercios_old.getIDCOMERCIO()+"' and  IDMUNICIPIO ='"+comercios_old.getIDMUNICIPIO()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setString(1,comercios.getIDCOMERCIO());pupdate.setString(14,comercios.getIDMUNICIPIO());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(Comercios comercios ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from comercios  where  IDCOMERCIO = ? and  IDMUNICIPIO = ?  ";
      pdelete= con.prepareStatement(sql);
      pdelete.setString(1,comercios.getIDCOMERCIO());
pdelete.setString(14,comercios.getIDMUNICIPIO());
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(String sqldelete ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from comercios where " + sqldelete +"";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* deleteAll()
*/

public static boolean deleteAll() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from comercios  ";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodeleteall"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* exists()
*/



public static boolean exists(Comercios comercios) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      String sql = "select * from comercios where IDCOMERCIO='"+comercios.getIDCOMERCIO()+"' and IDMUNICIPIO='"+comercios.getIDMUNICIPIO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +" " + bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return false;
   }
    rs.close();
    psquery.close();
 return true;
} catch (Exception ex) {
      excepcion = ex;
}
  return false;
}


/**
*
* findByPrimaryKey()
*/



public static Comercios findByPrimaryKey(Comercios comercios) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      String sql = "select * from comercios where IDCOMERCIO='"+comercios.getIDCOMERCIO()+"' and IDMUNICIPIO='"+comercios.getIDMUNICIPIO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
            
            
            comercios.setIDCOMERCIO(rs.getString("IDCOMERCIO"));
comercios.setCEDULA(rs.getString("CEDULA"));
comercios.setCOMERCIO(rs.getString("COMERCIO"));
comercios.setRUC(rs.getString("RUC"));
comercios.setDESCRIPCION(rs.getString("DESCRIPCION"));
comercios.setDIRECCION(rs.getString("DIRECCION"));
comercios.setIDCORREGIMIENTO(rs.getString("IDCORREGIMIENTO"));
comercios.setTELEFONO(rs.getString("TELEFONO"));
comercios.setFECHA(rs.getDate("FECHA"));
comercios.setHIPOTECADO(rs.getString("HIPOTECADO"));
comercios.setBAJADO(rs.getString("BAJADO"));
comercios.setTRASPASO(rs.getString("TRASPASO"));
comercios.setSECUESTRADO(rs.getString("SECUESTRADO"));
comercios.setIDMUNICIPIO(rs.getString("IDMUNICIPIO"));
comercios.setESTATAL(rs.getString("ESTATAL"));
comercios.setACTIVO(rs.getString("ACTIVO"));
comercios.setIDUSUARIO(rs.getString("IDUSUARIO"));
    }
    rs.close();
    psquery.close();
 return comercios;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIDCOMERCIO()
*/

public static List<Comercios> findByIDCOMERCIO(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where IDCOMERCIO='"+comercios.getIDCOMERCIO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("IDCOMERCIO"),rs.getString("CEDULA"),rs.getString("COMERCIO"),rs.getString("RUC"),rs.getString("DESCRIPCION"),rs.getString("DIRECCION"),rs.getString("IDCORREGIMIENTO"),rs.getString("TELEFONO"),rs.getDate("FECHA"),rs.getString("HIPOTECADO"),rs.getString("BAJADO"),rs.getString("TRASPASO"),rs.getString("SECUESTRADO"),rs.getString("IDMUNICIPIO"),rs.getString("ESTATAL"),rs.getString("ACTIVO"),rs.getString("IDUSUARIO"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByCEDULA()
*/

public static List<Comercios> findByCEDULA(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where CEDULA='"+comercios.getCEDULA()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("IDCOMERCIO"),rs.getString("CEDULA"),rs.getString("COMERCIO"),rs.getString("RUC"),rs.getString("DESCRIPCION"),rs.getString("DIRECCION"),rs.getString("IDCORREGIMIENTO"),rs.getString("TELEFONO"),rs.getDate("FECHA"),rs.getString("HIPOTECADO"),rs.getString("BAJADO"),rs.getString("TRASPASO"),rs.getString("SECUESTRADO"),rs.getString("IDMUNICIPIO"),rs.getString("ESTATAL"),rs.getString("ACTIVO"),rs.getString("IDUSUARIO"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByCOMERCIO()
*/

public static List<Comercios> findByCOMERCIO(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where COMERCIO='"+comercios.getCOMERCIO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("IDCOMERCIO"),rs.getString("CEDULA"),rs.getString("COMERCIO"),rs.getString("RUC"),rs.getString("DESCRIPCION"),rs.getString("DIRECCION"),rs.getString("IDCORREGIMIENTO"),rs.getString("TELEFONO"),rs.getDate("FECHA"),rs.getString("HIPOTECADO"),rs.getString("BAJADO"),rs.getString("TRASPASO"),rs.getString("SECUESTRADO"),rs.getString("IDMUNICIPIO"),rs.getString("ESTATAL"),rs.getString("ACTIVO"),rs.getString("IDUSUARIO"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByRUC()
*/

public static List<Comercios> findByRUC(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where RUC='"+comercios.getRUC()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("IDCOMERCIO"),rs.getString("CEDULA"),rs.getString("COMERCIO"),rs.getString("RUC"),rs.getString("DESCRIPCION"),rs.getString("DIRECCION"),rs.getString("IDCORREGIMIENTO"),rs.getString("TELEFONO"),rs.getDate("FECHA"),rs.getString("HIPOTECADO"),rs.getString("BAJADO"),rs.getString("TRASPASO"),rs.getString("SECUESTRADO"),rs.getString("IDMUNICIPIO"),rs.getString("ESTATAL"),rs.getString("ACTIVO"),rs.getString("IDUSUARIO"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByDESCRIPCION()
*/

public static List<Comercios> findByDESCRIPCION(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where DESCRIPCION='"+comercios.getDESCRIPCION()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("IDCOMERCIO"),rs.getString("CEDULA"),rs.getString("COMERCIO"),rs.getString("RUC"),rs.getString("DESCRIPCION"),rs.getString("DIRECCION"),rs.getString("IDCORREGIMIENTO"),rs.getString("TELEFONO"),rs.getDate("FECHA"),rs.getString("HIPOTECADO"),rs.getString("BAJADO"),rs.getString("TRASPASO"),rs.getString("SECUESTRADO"),rs.getString("IDMUNICIPIO"),rs.getString("ESTATAL"),rs.getString("ACTIVO"),rs.getString("IDUSUARIO"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByDIRECCION()
*/

public static List<Comercios> findByDIRECCION(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where DIRECCION='"+comercios.getDIRECCION()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("IDCOMERCIO"),rs.getString("CEDULA"),rs.getString("COMERCIO"),rs.getString("RUC"),rs.getString("DESCRIPCION"),rs.getString("DIRECCION"),rs.getString("IDCORREGIMIENTO"),rs.getString("TELEFONO"),rs.getDate("FECHA"),rs.getString("HIPOTECADO"),rs.getString("BAJADO"),rs.getString("TRASPASO"),rs.getString("SECUESTRADO"),rs.getString("IDMUNICIPIO"),rs.getString("ESTATAL"),rs.getString("ACTIVO"),rs.getString("IDUSUARIO"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIDCORREGIMIENTO()
*/

public static List<Comercios> findByIDCORREGIMIENTO(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where IDCORREGIMIENTO='"+comercios.getIDCORREGIMIENTO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("IDCOMERCIO"),rs.getString("CEDULA"),rs.getString("COMERCIO"),rs.getString("RUC"),rs.getString("DESCRIPCION"),rs.getString("DIRECCION"),rs.getString("IDCORREGIMIENTO"),rs.getString("TELEFONO"),rs.getDate("FECHA"),rs.getString("HIPOTECADO"),rs.getString("BAJADO"),rs.getString("TRASPASO"),rs.getString("SECUESTRADO"),rs.getString("IDMUNICIPIO"),rs.getString("ESTATAL"),rs.getString("ACTIVO"),rs.getString("IDUSUARIO"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByTELEFONO()
*/

public static List<Comercios> findByTELEFONO(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where TELEFONO='"+comercios.getTELEFONO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("IDCOMERCIO"),rs.getString("CEDULA"),rs.getString("COMERCIO"),rs.getString("RUC"),rs.getString("DESCRIPCION"),rs.getString("DIRECCION"),rs.getString("IDCORREGIMIENTO"),rs.getString("TELEFONO"),rs.getDate("FECHA"),rs.getString("HIPOTECADO"),rs.getString("BAJADO"),rs.getString("TRASPASO"),rs.getString("SECUESTRADO"),rs.getString("IDMUNICIPIO"),rs.getString("ESTATAL"),rs.getString("ACTIVO"),rs.getString("IDUSUARIO"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFECHA()
*/

public static List<Comercios> findByFECHA(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where FECHA='"+comercios.getFECHA()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("IDCOMERCIO"),rs.getString("CEDULA"),rs.getString("COMERCIO"),rs.getString("RUC"),rs.getString("DESCRIPCION"),rs.getString("DIRECCION"),rs.getString("IDCORREGIMIENTO"),rs.getString("TELEFONO"),rs.getDate("FECHA"),rs.getString("HIPOTECADO"),rs.getString("BAJADO"),rs.getString("TRASPASO"),rs.getString("SECUESTRADO"),rs.getString("IDMUNICIPIO"),rs.getString("ESTATAL"),rs.getString("ACTIVO"),rs.getString("IDUSUARIO"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByHIPOTECADO()
*/

public static List<Comercios> findByHIPOTECADO(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where HIPOTECADO='"+comercios.getHIPOTECADO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("IDCOMERCIO"),rs.getString("CEDULA"),rs.getString("COMERCIO"),rs.getString("RUC"),rs.getString("DESCRIPCION"),rs.getString("DIRECCION"),rs.getString("IDCORREGIMIENTO"),rs.getString("TELEFONO"),rs.getDate("FECHA"),rs.getString("HIPOTECADO"),rs.getString("BAJADO"),rs.getString("TRASPASO"),rs.getString("SECUESTRADO"),rs.getString("IDMUNICIPIO"),rs.getString("ESTATAL"),rs.getString("ACTIVO"),rs.getString("IDUSUARIO"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByBAJADO()
*/

public static List<Comercios> findByBAJADO(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where BAJADO='"+comercios.getBAJADO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("IDCOMERCIO"),rs.getString("CEDULA"),rs.getString("COMERCIO"),rs.getString("RUC"),rs.getString("DESCRIPCION"),rs.getString("DIRECCION"),rs.getString("IDCORREGIMIENTO"),rs.getString("TELEFONO"),rs.getDate("FECHA"),rs.getString("HIPOTECADO"),rs.getString("BAJADO"),rs.getString("TRASPASO"),rs.getString("SECUESTRADO"),rs.getString("IDMUNICIPIO"),rs.getString("ESTATAL"),rs.getString("ACTIVO"),rs.getString("IDUSUARIO"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByTRASPASO()
*/

public static List<Comercios> findByTRASPASO(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where TRASPASO='"+comercios.getTRASPASO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("IDCOMERCIO"),rs.getString("CEDULA"),rs.getString("COMERCIO"),rs.getString("RUC"),rs.getString("DESCRIPCION"),rs.getString("DIRECCION"),rs.getString("IDCORREGIMIENTO"),rs.getString("TELEFONO"),rs.getDate("FECHA"),rs.getString("HIPOTECADO"),rs.getString("BAJADO"),rs.getString("TRASPASO"),rs.getString("SECUESTRADO"),rs.getString("IDMUNICIPIO"),rs.getString("ESTATAL"),rs.getString("ACTIVO"),rs.getString("IDUSUARIO"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findBySECUESTRADO()
*/

public static List<Comercios> findBySECUESTRADO(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where SECUESTRADO='"+comercios.getSECUESTRADO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("IDCOMERCIO"),rs.getString("CEDULA"),rs.getString("COMERCIO"),rs.getString("RUC"),rs.getString("DESCRIPCION"),rs.getString("DIRECCION"),rs.getString("IDCORREGIMIENTO"),rs.getString("TELEFONO"),rs.getDate("FECHA"),rs.getString("HIPOTECADO"),rs.getString("BAJADO"),rs.getString("TRASPASO"),rs.getString("SECUESTRADO"),rs.getString("IDMUNICIPIO"),rs.getString("ESTATAL"),rs.getString("ACTIVO"),rs.getString("IDUSUARIO"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIDMUNICIPIO()
*/

public static List<Comercios> findByIDMUNICIPIO(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where IDMUNICIPIO='"+comercios.getIDMUNICIPIO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("IDCOMERCIO"),rs.getString("CEDULA"),rs.getString("COMERCIO"),rs.getString("RUC"),rs.getString("DESCRIPCION"),rs.getString("DIRECCION"),rs.getString("IDCORREGIMIENTO"),rs.getString("TELEFONO"),rs.getDate("FECHA"),rs.getString("HIPOTECADO"),rs.getString("BAJADO"),rs.getString("TRASPASO"),rs.getString("SECUESTRADO"),rs.getString("IDMUNICIPIO"),rs.getString("ESTATAL"),rs.getString("ACTIVO"),rs.getString("IDUSUARIO"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByESTATAL()
*/

public static List<Comercios> findByESTATAL(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where ESTATAL='"+comercios.getESTATAL()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("IDCOMERCIO"),rs.getString("CEDULA"),rs.getString("COMERCIO"),rs.getString("RUC"),rs.getString("DESCRIPCION"),rs.getString("DIRECCION"),rs.getString("IDCORREGIMIENTO"),rs.getString("TELEFONO"),rs.getDate("FECHA"),rs.getString("HIPOTECADO"),rs.getString("BAJADO"),rs.getString("TRASPASO"),rs.getString("SECUESTRADO"),rs.getString("IDMUNICIPIO"),rs.getString("ESTATAL"),rs.getString("ACTIVO"),rs.getString("IDUSUARIO"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByACTIVO()
*/

public static List<Comercios> findByACTIVO(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where ACTIVO='"+comercios.getACTIVO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("IDCOMERCIO"),rs.getString("CEDULA"),rs.getString("COMERCIO"),rs.getString("RUC"),rs.getString("DESCRIPCION"),rs.getString("DIRECCION"),rs.getString("IDCORREGIMIENTO"),rs.getString("TELEFONO"),rs.getDate("FECHA"),rs.getString("HIPOTECADO"),rs.getString("BAJADO"),rs.getString("TRASPASO"),rs.getString("SECUESTRADO"),rs.getString("IDMUNICIPIO"),rs.getString("ESTATAL"),rs.getString("ACTIVO"),rs.getString("IDUSUARIO"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIDUSUARIO()
*/

public static List<Comercios> findByIDUSUARIO(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where IDUSUARIO='"+comercios.getIDUSUARIO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("IDCOMERCIO"),rs.getString("CEDULA"),rs.getString("COMERCIO"),rs.getString("RUC"),rs.getString("DESCRIPCION"),rs.getString("DIRECCION"),rs.getString("IDCORREGIMIENTO"),rs.getString("TELEFONO"),rs.getDate("FECHA"),rs.getString("HIPOTECADO"),rs.getString("BAJADO"),rs.getString("TRASPASO"),rs.getString("SECUESTRADO"),rs.getString("IDMUNICIPIO"),rs.getString("ESTATAL"),rs.getString("ACTIVO"),rs.getString("IDUSUARIO"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* locateByParameters()
*/

public static List<Comercios> locateByParameters(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
  String sql = "select * from comercios";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      int i = 0;
      while (it.hasNext()) {
          if (i != 0){
            sb.append(" and ");
         }
         i++;
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"= '"+  e.getValue()+"'");
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("IDCOMERCIO"),rs.getString("CEDULA"),rs.getString("COMERCIO"),rs.getString("RUC"),rs.getString("DESCRIPCION"),rs.getString("DIRECCION"),rs.getString("IDCORREGIMIENTO"),rs.getString("TELEFONO"),rs.getDate("FECHA"),rs.getString("HIPOTECADO"),rs.getString("BAJADO"),rs.getString("TRASPASO"),rs.getString("SECUESTRADO"),rs.getString("IDMUNICIPIO"),rs.getString("ESTATAL"),rs.getString("ACTIVO"),rs.getString("IDUSUARIO"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* Double fFunc(String funcion, String campo)
*/



public static Double func(String funcion, String campo) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from comercios";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* Double func(String funcion, String campo,String where)
*/



public static Double func(String funcion, String campo, String where) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from comercios where "+where +" ";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* count()
*/



public static Integer count() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from comercios";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* count(String sqlquery)
*/



public static Integer count(String sqlquery) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from comercios where  " + sqlquery +"";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* query()
*/

public static List<Comercios> query(String query,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<Comercios>();
  String sql = "select * from comercios where " + query +"";
  if (query == null || query.equals("")) {
  return null;
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("IDCOMERCIO"),rs.getString("CEDULA"),rs.getString("COMERCIO"),rs.getString("RUC"),rs.getString("DESCRIPCION"),rs.getString("DIRECCION"),rs.getString("IDCORREGIMIENTO"),rs.getString("TELEFONO"),rs.getDate("FECHA"),rs.getString("HIPOTECADO"),rs.getString("BAJADO"),rs.getString("TRASPASO"),rs.getString("SECUESTRADO"),rs.getString("IDMUNICIPIO"),rs.getString("ESTATAL"),rs.getString("ACTIVO"),rs.getString("IDUSUARIO"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* getListRecords()
*/

public static List<Comercios> getListRecords(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      list = new ArrayList<Comercios>();
  String sql = "select * from comercios";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      while (it.hasNext()) {
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"="+  e.getValue());
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
       
        Comercios comercios2 = new Comercios(
         rs.getString("IDCOMERCIO"),rs.getString("CEDULA"),rs.getString("COMERCIO"),rs.getString("RUC"),rs.getString("DESCRIPCION"),rs.getString("DIRECCION"),rs.getString("IDCORREGIMIENTO"),rs.getString("TELEFONO"),rs.getDate("FECHA"),rs.getString("HIPOTECADO"),rs.getString("BAJADO"),rs.getString("TRASPASO"),rs.getString("SECUESTRADO"),rs.getString("IDMUNICIPIO"),rs.getString("ESTATAL"),rs.getString("ACTIVO"),rs.getString("IDUSUARIO"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
 }


}
